﻿using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using élénkPróbája.results;

namespace élénkPróbája
{
    public interface IValidationRule
    {

        /// <summary>
        /// The validators that are grouped under this rule.
        /// </summary>
        IEnumerable<ILitPropertyValidator> Validators { get; }
        /// <summary>
        /// Name of the rule-set to which this rule belongs.
        /// </summary>
        string RuleSet { get; set; }

        /// <summary>
        /// Performs validation using a validation context and returns a collection of Validation Failures.
        /// </summary>
        /// <param name="context">Validation Context</param>
        /// <returns>A collection of validation failures</returns>
        IEnumerable<ValidationFailure> Validate(ValidationContext context);

        /// <summary>
        /// Performs validation using a validation context and returns a collection of Validation Failures asynchronoulsy.
        /// </summary>
        /// <param name="context">Validation Context</param>
        /// <param name="cancellation">Cancellation token</param>
        /// <returns>A collection of validation failures</returns>
        Task<IEnumerable<ValidationFailure>> ValidateAsync(ValidationContext context, CancellationToken cancellation);

        void ApplyCondition(Func<object, bool> predicate, ApplyConditionTo applyConditionTo = ApplyConditionTo.AllValidators);

        void ApplyAsyncCondition(Func<object, Task<bool>> predicate, ApplyConditionTo applyConditionTo = ApplyConditionTo.AllValidators);
    }
}